/***************************************************************
 * Name:      main.cpp
 * Purpose:   MAICAM
 * Author:    Riku Maikola (riku@maikola.net)
 * Usage:     START MAICAM PROGRAM
 * Created:   2014-05-03 - 2014-05-03
 * Copyright: Riku Maikola
 * License:   GPL
 **************************************************************/

#include <iostream>
#include <unistd.h>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include "mGlobals.h"

using namespace std;

int main(int n, char* Args[])
{
    if(n==2)
    {
        string WORKDIR;
        WORKDIR = newDir("/dev/shm/maicam_");
        system( ("cd " + WORKDIR + "\ntar -xf " + Args[1]).c_str() );         //OPEN WORKDIR
        LineChange( (WORKDIR + "/prefs").c_str() ,0 , Args[1]);
        LineChange( (WORKDIR + "/prefs").c_str() ,1 , WORKDIR.c_str());

        system(("~/MAICAM/bin/UI " + WORKDIR + " &").c_str());

        //**
        chdir(WORKDIR.c_str());     //set workdirectory
        int UpdateTime=0;
        while(FileIsUpdated(&UpdateTime,"reg"))sleep(3);

        SaveProject();
        ClearProject();
        std::cout << "\n exiting maicam\n\n";
        return 1;

    }
    else
    {
       return 0;
    }



 /*   if(n==2)
    {




        string directory;
        string filename = Args[2];

        //getcwd();
        //system("cd /dev/shm/");
        //char directory[1024];
        chdir("/home/rpm/MAICAM");
        system("./bin/UI &");

        chdir("/dev/shm/"); //current directory...


directory = get_current_dir_name();
        cout << directory << "\n";

        if(Args[1][0]==102)
        {
            cout << filename << " execute file\n";
        }
        else if(Args[1][0]==108)
        {
            cout << filename << " execute line\n";
        }




            rows.erase(rows.end()-1,rows.end());    //erase the space between prorgrams
            rows.push_back("%");
            codefile.close();


            vector<string> rows;

            rows.push_back("test");

            ofstream myfile;
            myfile.open("out");
            if(myfile.is_open() && (rows.size()>0))
            {
                for(uint b=0; b<rows.size(); b++)myfile << rows[b] << "\n";
                myfile.close();
            }
    }*/
    return 0;
}


